// pages/jiesuan/jiesuan.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    names: "",
    phones: "",
    dizhi: "",
    qiang: [],
    item: [],
    name: "",
    img: "",
    userId: "",
    list: "",
    number: "",
    addrId: "",
    money: "",
    biaoshi: "",
    goods_list:"",
    city:"",
    detail:"",
    district:"",
    total:"",



  },
  // 购物
  gouwu() {
    // if (app.globalData.qq == 0) {
      console.log("购物车")
      wx.request({
        url: 'http://123.206.228.246:50080/wxone/cart/getAll', //仅为示例，并非真实的接口地址
        method: 'POST',
        data: {
          userId: app.globalData.userId
        },
        header: {
          Content_Type: "application/json"
        },
        success: (res) => {
          // console.log(app.globalData.qq)
          console.log("jiazaigouwufangfa")
          console.log(res)
          app.globalData.list = res.data.data.goods_list
          this.lang(app.globalData.list)
          console.log("值")
          console.log(res.data.data.goods_list)
          this.setData({
            list: res.data.data.goods_list,
            qq: 0
          })
          wx.request({
            url: 'http://123.206.228.246:50080/wxone/order/settle', //仅为示例，并非真实的接口地址
            method: 'POST',
            data: {
              userId: app.globalData.userId,
              goods_list: this.data.list
            },
            header: {
              Content_Type: "application/json"
            },
            success: (res) => {
              console.log("结算")
              console.log(res)
              this.setData({
                goods_list: res.data.data.good_list,
                item: res.data.data,
                total: res.data.data.total_money
              })
              console.log(this.data.goods_list)
            }
          })
        }
      })
    // } else if (app.globalData.qq == 1) {
      console.log("详情")
      // wx.request({
      //   url: 'http://123.206.228.246:50080/wxone/goods/goodsDetails', //仅为示例，并非真实的接口地址
      //   method: 'POST',
      //   data: {
      //     goodsId: app.globalData.id,
      //   },
      //   header: {
      //     Content_Type: "application/json"
      //   },
      //   success: (res) => {
      //     console.log("商品详情")
      //     console.log(res)
      //     // console.log(app.globalData.id)
      //     this.lang(app.globalData.list)
      //     // console.log(app.globalData.list)
      //     this.setData({
      //       name: res.data.data.name,
      //       img: res.data.data.image,
      //       price: res.data.data.price,
      //       qq: 1,

      //     })


      //   }
      // })
    // }

  },
  // 结算页面
  lang:function() {
  },
  dizhi:function() {
    wx.navigateTo({
      url: '../zhanghu/shouhuodz/shouhuodz',
    })
    wx.request({
      
      url: 'http://123.206.228.246:50080/wxone/address/all',
      method: 'POST',
      data: {
        userId: app.globalData.userId,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: (res) => {
        console.log("地址")
        console.log(res)
        this.setData({
          names:res.data.data[0].name,
          city:res.data.data[0].city,
          district:res.data.data[0].district,
          detail: res.data.data[0].detail,
          phones:res.data.data[0].phone


          
        })
      } 
    })
  },

  btn: function () {
    wx.reLaunch({
      url: '../shangdian/shangdian'
    }),
    wx.request({
      url: 'http://123.206.228.246:50080/wxone/order/create', //仅为示例，并非真实的接口地址
      method: 'POST',
      data: {
        userId: app.globalData.userId,
        money: app.globalData.money1 + '',
        addrId: app.globalData.addrId,
        goods_list: app.globalData.list,
        message: "78787888",
        flag: "0" //0 购物车 1 详情页
      },
      header: {
        Content_Type: "application/json"
      },
      success: (res) => {
        wx.showToast({
          title: '购买成功',
          icon: 'success',
          duration: 2000
        })
        console.log("生成订单")
        console.log(res)
        // this.setData({
        //   item: res.data.data.good_list
        // })
      }
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.dizhi()
    // console.log(options.lx)
    this.gouwu()
    console.log("45455454")
    console.log(options.id)
    this.setData({
      id: options.id
    })


  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // console.log(options.lx)
    this.gouwu()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})